/**
 * 
 */
package com.geezdata.cps.sdk3rd.wechat.method;

import java.util.Map;

import com.geezdata.cps.sdk3rd.wechat.request.WechatQrCodeReqeust;
import com.geezdata.cps.sdk3rd.wechat.response.WechatQrCodeResult;
import com.google.common.collect.Maps;

/**
 * @author sszheng
 * @date 创建时间：2018年3月29日 下午4:32:39
 *
 */
public class WechatQrCode extends BaseWechat implements Wechat<WechatQrCodeReqeust, WechatQrCodeResult> {
	private static final String QRCODE_URL = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=";
	
	@Override
	public WechatQrCodeResult execute(WechatQrCodeReqeust request) {
		Map<String, Object> params = prepareParams(request);
		return doPost(QRCODE_URL + request.getToken(), params, WechatQrCodeResult.class);
	}
	private Map<String, Object> prepareParams(WechatQrCodeReqeust request) {
		Map<String, Object> map = Maps.newHashMap();
		Map<String, Object> actionInfo = Maps.newHashMap();
		Map<String, String> scene = Maps.newHashMap();
		scene.put("scene_str", request.getActionInfo().getMobile());
		actionInfo.put("scene", scene);
		map.put("action_name", request.getActionName());
		map.put("expire_seconds", request.getExpireSeconds());
		map.put("action_info", actionInfo);
		return map;
	}
}
